package com.bicon.base.data.quartz.job;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;

import com.bicon.base.data.pojo.quartz.job.Job;
import com.bicon.base.data.service.quartz.job.IJobService;

@Component
public class JobMessageReceiver {
	
	@Autowired
	private IJobService jobService;
	private Method method;

	//@RabbitListener(queues = "${spring.rabbitmq.currentQueue}")
	//@RabbitHandler
	public void receiveMessage(Job message) {
		try {
			//获取逻辑处理方法
			this.method = jobService.getClass().getDeclaredMethod(message.getRemark(),Job.class);
			ReflectionUtils.makeAccessible(method);
			//反射调用
			method.invoke(jobService,message);
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		}catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}

	}
}
